﻿# Support Northern Court
shogunate_support_northern_court_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_knight_kneeling.dds"
	}
	decision_group_type = shogunate_major

	ai_check_interval = 12

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_trait = southern_court
				}
				desc = shogunate_support_northern_court_decision_desc_betrayer
			}
			desc = shogunate_support_northern_court_decision_desc
		}
	}

	selection_tooltip = shogunate_support_northern_court_decision_tooltip

	is_shown = {
		shogunate_is_nanbokucho_period_trigger = yes
		shogunate_has_yamato_culture_trigger = yes
		NOT = { has_trait = northern_court }
		NOR = {
			has_title = title:e_nmih_japan
			has_title = title:e_nmih_tenno
			has_title = title:e_nmih_joko
			has_title = title:e_nmih_nancho
			has_title = title:e_nmih_third_force
		}
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		domain_size > 0
	}

	is_valid = {
		is_independent_ruler = yes
		trigger_if = {
			limit = {
				is_ai = no
			}
			title:e_nmih_japan.holder = {
				opinion = {
					target = root
					value >= 0
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available = yes
		is_at_war = no
	}

	effect = {
		save_scope_as = supporter

		if = {
			limit = {
				has_trait = southern_court
			}
			hidden_effect = {
				save_scope_as = betrayer
				remove_trait = southern_court
				add_trait = northern_court
			}
			add_character_modifier = {
				modifier = shogunate_betrayer_modifier
				years = 10
			}
		}
		else_if = {
			limit = {
				has_trait = third_force
			}
			hidden_effect = {
				remove_trait = third_force
				add_trait = northern_court
			}
			add_character_modifier = {
				modifier = shogunate_betrayer_modifier
				years = 10
			}
		}
		else = {
			add_trait = northern_court
		}

		trigger_event = shogunate_nanbokucho.0003

		every_player = {
			limit = {
				NOT = { this = root }
			}
			trigger_event = shogunate_nanbokucho.0004
		}
	}

	ai_potential = {
		exists = title:e_nmih_japan.holder
		title:e_nmih_japan.holder = {
			opinion = {
				target = root
				value >= -25
			}
		}
	}

	ai_will_do = {
		base = 0

		modifier = {
			opinion = {
				target = title:e_nmih_japan.holder
				value >= 50
			}
			add = 20
		}

		modifier = {
			opinion = {
				target = title:e_nmih_nancho.holder
				value >= 50
			}
			add = -20
		}

		modifier = {
			opinion = {
				target = title:e_nmih_nancho.holder
				value <= -50
			}
			add = 50
		}

		modifier = {
			has_trait = disloyal
			add = 20
		}

		modifier = {
			has_trait = ambitious
			add = 20
		}

		modifier = {
			has_trait = paranoid
			add = 20
		}

		modifier = {
			has_trait = deceitful
			add = 10
		}

		modifier = {
			has_trait = arbitrary
			add = 10
		}

		modifier = {
			has_trait = loyal
			add = -1000
		}

		modifier = {
			has_trait = content
			add = -50
		}

		modifier = {
			has_trait = trusting
			add = -50
		}

		modifier = {
			has_trait = honest
			add = -20
		}

		modifier = {
			has_trait = just
			add = -20
		}

		modifier = {
			title:c_nmih_otagi.holder.top_liege = {									# Kyoto
				has_trait = northern_court
			}
			add = 20
		}

		modifier = {
			title:c_nmih_kamakura.holder.top_liege = {								# Kamakura
				has_trait = northern_court
			}
			add = 10
		}

		modifier = {
			title:c_nmih_mikasa.holder.top_liege = {								# Dazaifu
				has_trait = northern_court
			}
			add = 10
		}

		modifier = {
			title:c_nmih_miyagi.holder.top_liege = {								# Taga Castle
				has_trait = northern_court
			}
			add = 10
		}

		modifier = {
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = northern_court
					}
					percent >= 0.5
				}
			}
			add = 20
		}

		modifier = {
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = northern_court
					}
					percent >= 0.6
				}
			}
			add = 50
		}

		modifier = {
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = southern_court
					}
					percent >= 0.5
				}
			}
			add = -20
		}

		modifier = {
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = southern_court
					}
					percent >= 0.6
				}
			}
			add = -1000
		}

		modifier = {
			OR = {
				highest_held_title_tier >= tier_kingdom
				NOT = { has_trait = southern_court }
			}
			add = -50
		}

		modifier = {
			OR = {
				dynasty = dynasty:10000420		# Yamato
				dynasty = dynasty:10000260		# Kitabatake
				dynasty = dynasty:10006129		# Hojo (Kamakura)
			}
			add = -1000
		}
	}
}


# Support Southern Court
shogunate_support_southern_court_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_knight_kneeling.dds"
	}
	decision_group_type = shogunate_major

	ai_check_interval = 12

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_trait = northern_court
				}
				desc = shogunate_support_southern_court_decision_desc_betrayer
			}
			desc = shogunate_support_southern_court_decision_desc
		}
	}

	selection_tooltip = shogunate_support_southern_court_decision_tooltip

	is_shown = {
		shogunate_is_nanbokucho_period_trigger = yes
		shogunate_has_yamato_culture_trigger = yes
		NOT = { has_trait = southern_court }
		NOR = {
			has_title = title:e_nmih_japan
			has_title = title:e_nmih_tenno
			has_title = title:e_nmih_joko
			has_title = title:e_nmih_nancho
			has_title = title:e_nmih_third_force
		}
		OR = {
			government_has_flag = government_is_feudal
			government_has_flag = government_is_administrative
		}
		domain_size > 0
	}

	is_valid = {
		is_independent_ruler = yes
		trigger_if = {
			limit = {
				is_ai = no
			}
			title:e_nmih_nancho.holder = {
				opinion = {
					target = root
					value >= 0
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available = yes
		is_at_war = no
	}

	effect = {
		save_scope_as = supporter

		if = {
			limit = {
				has_trait = northern_court
			}
			hidden_effect = {
				save_scope_as = betrayer
				remove_trait = northern_court
				add_trait = southern_court
			}
			add_character_modifier = {
				modifier = shogunate_betrayer_modifier
				years = 10
			}
		}
		else_if = {
			limit = {
				has_trait = third_force
			}
			hidden_effect = {
				remove_trait = third_force
				add_trait = southern_court
			}
			add_character_modifier = {
				modifier = shogunate_betrayer_modifier
				years = 10
			}
		}
		else = {
			add_trait = southern_court
		}

		trigger_event = shogunate_nanbokucho.0003

		every_player = {
			limit = {
				NOT = { this = root }
			}
			trigger_event = shogunate_nanbokucho.0005
		}
	}

	ai_potential = {
		exists = title:e_nmih_nancho.holder
		title:e_nmih_nancho.holder = {
			opinion = {
				target = root
				value >= -25
			}
		}
	}

	ai_will_do = {
		base = 0

		modifier = {
			opinion = {
				target = title:e_nmih_nancho.holder
				value >= 50
			}
			add = 20
		}

		modifier = {
			opinion = {
				target = title:e_nmih_japan.holder
				value >= 50
			}
			add = -20
		}

		modifier = {
			opinion = {
				target = title:e_nmih_japan.holder
				value <= -50
			}
			add = 50
		}

		modifier = {
			has_trait = disloyal
			add = 20
		}

		modifier = {
			has_trait = ambitious
			add = 20
		}

		modifier = {
			has_trait = paranoid
			add = 20
		}

		modifier = {
			has_trait = deceitful
			add = 10
		}

		modifier = {
			has_trait = arbitrary
			add = 10
		}

		modifier = {
			has_trait = loyal
			add = -1000
		}

		modifier = {
			has_trait = content
			add = -50
		}

		modifier = {
			has_trait = trusting
			add = -50
		}

		modifier = {
			has_trait = honest
			add = -20
		}

		modifier = {
			has_trait = just
			add = -20
		}

		modifier = {
			title:c_nmih_otagi.holder.top_liege = {									# Kyoto
				has_trait = southern_court
			}
			add = 20
		}

		modifier = {
			title:c_nmih_kamakura.holder.top_liege = {								# Kamakura
				has_trait = southern_court
			}
			add = 10
		}

		modifier = {
			title:c_nmih_mikasa.holder.top_liege = {								# Dazaifu
				has_trait = southern_court
			}
			add = 10
		}

		modifier = {
			title:c_nmih_miyagi.holder.top_liege = {								# Taga Castle
				has_trait = southern_court
			}
			add = 10
		}

		modifier = {
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = southern_court
					}
					percent >= 0.5
				}
			}
			add = 20
		}

		modifier = {
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = southern_court
					}
					percent >= 0.6
				}
			}
			add = 50
		}

		modifier = {
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = northern_court
					}
					percent >= 0.5
				}
			}
			add = -20
		}

		modifier = {
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = northern_court
					}
					percent >= 0.6
				}
			}
			add = -1000
		}

		modifier = {
			OR = {
				highest_held_title_tier >= tier_kingdom
				NOT = { has_trait = northern_court }
			}
			add = -50
		}

		modifier = {
			OR = {
				dynasty = dynasty:10000400		# Ashikaga
			}
			add = -50
		}
	}
}

# Unify the Two Courts by the Northern Court
shogunate_unify_two_courts_by_northern_court_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_destiny_goal.dds"
	}
	decision_group_type = shogunate_major

	ai_goal = yes

	desc = shogunate_unify_two_courts_by_northern_court_decision_desc
	selection_tooltip = shogunate_unify_two_courts_by_northern_court_decision_tooltip

	is_shown = {
		shogunate_is_nanbokucho_period_trigger = yes
		has_trait = northern_court
	}

	is_valid = {
		has_title = title:e_nmih_japan
		custom_description = {
			text = shogunate_unify_two_courts_by_northern_court_decision_realm_size_trigger
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = northern_court
					}
					percent >= 0.8
				}
			}
		}
		custom_description = {
			text = shogunate_unify_two_courts_decision_kyoto_trigger
			title:c_nmih_otagi.holder.top_liege = {									# Kyoto
				has_trait = northern_court
			}
		}
		custom_description = {
			text = shogunate_unify_two_courts_decision_kamakura_trigger
			title:c_nmih_kamakura.holder.top_liege = {								# Kamakura
				has_trait = northern_court
			}
		}
		custom_description = {
			text = shogunate_unify_two_courts_decision_dazaifu_trigger
			title:c_nmih_mikasa.holder.top_liege = {								# Dazaifu
				has_trait = northern_court
			}
		}
		custom_description = {
			text = shogunate_unify_two_courts_decision_taga_trigger
			title:c_nmih_miyagi.holder.top_liege = {								# Taga Castle
				has_trait = northern_court
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available = yes
		is_at_war = no
	}

	effect = {
		hidden_effect = {
			title:e_nmih_nancho.holder = {
				shogunate_nanbokucho_remove_modifier_effect = yes
			}
		}
		destroy_title = title:e_nmih_nancho
		custom_tooltip = {
			text = shogunate_unify_two_courts_decision_effect.1
		}
		custom_tooltip = {
			text = shogunate_unify_two_courts_decision_effect.2
		}
		trigger_event = shogunate_nanbokucho.0006
	}
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}

# Unify the Two Courts by the Southern Court
shogunate_unify_two_courts_by_southern_court_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_destiny_goal.dds"
	}
	decision_group_type = shogunate_major

	ai_goal = yes

	desc = shogunate_unify_two_courts_by_southern_court_decision_desc
	selection_tooltip = shogunate_unify_two_courts_by_southern_court_decision_tooltip

	is_shown = {
		shogunate_is_nanbokucho_period_trigger = yes
		has_trait = southern_court
	}

	is_valid = {
		dynasty = dynasty:10000420								# Yamato clan (Imperial family)
		has_title = title:e_nmih_nancho
		custom_description = {
			text = shogunate_unify_two_courts_by_southern_court_decision_realm_size_trigger
			title:e_nmih_japan = {
				any_de_jure_county = {
					holder = {
						has_trait = southern_court
					}
					percent >= 0.8
				}
			}
		}
		custom_description = {
			text = shogunate_unify_two_courts_decision_kyoto_trigger
			title:c_nmih_otagi.holder.top_liege = {									# Kyoto
				has_trait = southern_court
			}
		}
		custom_description = {
			text = shogunate_unify_two_courts_decision_kamakura_trigger
			title:c_nmih_kamakura.holder.top_liege = {								# Kamakura
				has_trait = southern_court
			}
		}
		custom_description = {
			text = shogunate_unify_two_courts_decision_dazaifu_trigger
			title:c_nmih_mikasa.holder.top_liege = {								# Dazaifu
				has_trait = southern_court
			}
		}
		custom_description = {
			text = shogunate_unify_two_courts_decision_taga_trigger
			title:c_nmih_miyagi.holder.top_liege = {								# Taga Castle
				has_trait = southern_court
			}
		}
	}

	is_valid_showing_failures_only = {
		is_available = yes
		is_at_war = no
	}

	effect = {
		hidden_effect = {
			title:e_nmih_japan.holder = {
				shogunate_nanbokucho_remove_modifier_effect = yes
			}
		}
		destroy_title = title:e_nmih_japan
		trigger_event = shogunate_nanbokucho.0006
		custom_tooltip = {
			text = shogunate_unify_two_courts_decision_effect.1
		}
		custom_tooltip = {
			text = shogunate_unify_two_courts_decision_effect.2
		}
	}
	
	ai_potential = {
		always = yes
	}

	ai_will_do = {
		base = 100
	}
}
